<?php

require_once '../include/common.inc.php';
if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}
$menu_index = 1;
$page_title = 'TABLA';
$guide_message = 'Product | Basic Information | Edit';


getMyParam('cid');

//ûϢ
$sql = "SELECT * FROM `pro_product` where id=$cid";
$query = $db->query($sql);
$pro_ary=$db->fetch_array($query);
//var_dump($pro_ary);

$old_pic=$pro_ary['pic'];
$old_video=$pro_ary['video'];
$order=$pro_ary['orders'];
if($pro_ary['pic']!="") $pro_ary['pic']="<img src='../pictures/pro_product/pic/{$pro_ary['pic']}' width='100' height='100'>";
else $pro_ary['pic']='No Pictures';

if($pro_ary['video']!="") $pro_ary['video']="<a href='../pictures/pro_product/video/{$pro_ary['video']}'>{$pro_ary['video_name']}</a>";
else $pro_ary['video']='No Video';


//type
$sql = "SELECT * FROM `pro_product_type` where product_id=$cid";
$query_type = $db->query($sql);
$flag=true;
$j=0;
while($type_temp=$db->fetch_array($query_type))
{
	$type_ary[$j]=$type_temp;
	$j++;
}


$sql = "SELECT `id`, `name` FROM `pro_type` where name!='Courses / Programs' ORDER BY `orders` ASC";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	
	for($i=0;$i<count($type_ary);$i++)
	{
		if($type_ary[$i]['type_id']==$rs['id']){
		$type_select.= "<tr class='tbcontent1'>
                      <td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='type_id[]' checked='checked' value='$rs[id]' onChange='if ( this.checked==true){type_order_$rs[id].disabled=false;} else {type_order_$rs[id].disabled=true;}' />$rs[name]</td>
						  </tr>";
		$flag=false;
		break;
		}			  
	}	
	
	if($flag){$type_select.= "<tr class='tbcontent1'>
                      <td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='type_id[]' value='$rs[id]' onChange='if ( this.checked==true){type_order_$rs[id].disabled=false;type_order_$rs[id].value=0} else {type_order_$rs[id].disabled=true;}' />$rs[name]</td>
						  </tr>";
	}
	$flag=true;
}

//category
$sql = "SELECT * FROM `pro_product_category` where product_id=$cid";
$query_category = $db->query($sql);


$flag=true;
$j=0;
while($category_temp=$db->fetch_array($query_category))
{
	$category_ary[$j]=$category_temp;
	$j++;
}


$sql = "SELECT `id`, `name` FROM `pro_category` ORDER BY `orders` ASC";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	
	for($i=0;$i<count($category_ary);$i++)
	{
		if($category_ary[$i]['category_id']==$rs['id']){
		$category_select.= "<tr class='tbcontent1'>
                      <td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='category_id[]' checked='checked' value='$rs[id]' onChange='if ( this.checked==true){category_order_$rs[id].disabled=false;} else {category_order_$rs[id].disabled=true;}' />$rs[name]</td>
						  </tr>";
		$flag=false;
		break;
		}			  
	}	
	
	if($flag){$category_select.= "<tr class='tbcontent1'>
                      <td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='category_id[]' value='$rs[id]' onChange='if ( this.checked==true){category_order_$rs[id].disabled=false;category_order_$rs[id].value=0} else {category_order_$rs[id].disabled=true;}' />$rs[name]</td>
						  </tr>";
	}
	$flag=true;
}


//Publisher
$sql = "SELECT `id`, `name` FROM `pro_publisher` ";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	if($rs['id']==$pro_ary['publiser_id'])	$publisher_select.="<option value='$rs[id]' selected='selected'>".$rs[name];
	else $publisher_select.= "<option value='$rs[id]'>".$rs[name];
}

//Author
$sql = "SELECT `id`, `name` FROM `pro_author` ";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	if($rs['id']==$pro_ary['author_id'])	$author_select.="<option value='$rs[id]' selected='selected'>".$rs[name];
	else $author_select.= "<option value='$rs[id]'>".$rs[name];
}

//Supplier
$sql = "SELECT `id`, `name` FROM `pro_supplier` ";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	if($rs['id']==$pro_ary['supplier_id'])	$supplier_select.="<option value='$rs[id]' selected='selected'>".$rs[name];
	else $supplier_select.= "<option value='$rs[id]'>".$rs[name];
}

//Stock Status
if($pro_ary['stock_status']==1){ $stock_select="<input type='radio' class='' name='stock_status' value='1' checked='checked'>&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='stock_status' value='0' >&nbsp;NO";}
else{  $stock_select="<input type='radio' class='' name='stock_status' value='1' >&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='stock_status' value='0' checked='checked'>&nbsp;NO";}

//Is BestSeller
if($pro_ary['is_best']==1){ $is_best_select="<input type='radio' class='' name='is_best' value='1' checked='checked'>&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_best' value='0' >&nbsp;NO";}
else{  $is_best_select="<input type='radio' class='' name='is_best' value='1' >&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_best' value='0' checked='checked'>&nbsp;NO";}
	
//Is Featured
if($pro_ary['is_featured']==1){ $is_featured_select="<input type='radio' class='' name='is_featured' value='1' checked='checked'>&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_featured' value='0' >&nbsp;NO";}
else{  $is_featured_select="<input type='radio' class='' name='is_featured' value='1' >&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_featured' value='0' checked='checked'>&nbsp;NO";}

//Is special
if($pro_ary['is_special']==1){ $is_special_select="<input type='radio' class='' name='is_special' value='1' checked='checked'>&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_special' value='0' >&nbsp;NO";}
else{  $is_special_select="<input type='radio' class='' name='is_special' value='1' >&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_special' value='0' checked='checked'>&nbsp;NO";}
//Is show
if($pro_ary['is_show']==1){ $is_show_select="<input type='radio' class='' name='is_show' value='1' checked='checked'>&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_show' value='0' >&nbsp;NO";}
else{  $is_show_select="<input type='radio' class='' name='is_show' value='1' >&nbsp;YES
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='radio' class='' name='is_show' value='0' checked='checked'>&nbsp;NO";}

include_once('menu_list.php');
require_once PrintEot('a_header');
require_once PrintEot('a_p_product_edit');
require_once PrintEot('a_footer');

?>